<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org/">
	<head>
		<meta charset="utf-8">
		<title>layuiAdmin 网站用户</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
		<script type="text/javascript" th:src="@{/public/jquery-3.4.1.js}"></script>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-card">
				<!-- 搜索栏div -->
				<div class="layui-form layui-card-header layuiadmin-card-header-auto">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">选择药品</label>
							<div class="layui-input-block">
			                    <select type="text" name="drug.drugDict_id" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">未选择</option>
			                        <option th:each="drug:${drugs}" th:value="${drug.drugDict_id}">[[${drug.drugDict_name}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">输入药品名</label><!--   -->
							<div class="layui-input-block">
								<input type="text" name="drug.drugDict_name" id="drugDict_name" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off"  
									style="position:absolute;z-index:2;width:86%;">
			                    <select type="text" id="SelectId-drugDict_name" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="drug:${drugs}" th:value="${drug.drugDict_id}">[[${drug.drugDict_name}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">批次</label>
							<div class="layui-input-block">
								<input type="text" name="instock.is_batch" id="is_batch" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_batch" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_id}">[[${item.is_batch}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline" style="margin-right: 0px;">
							<label class="layui-form-label">数量</label>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="ds_num_min" lay-verify="geZeroOrNull" lay-verType="tips" placeholder="" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">~</div>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="ds_num_max" lay-verify="geZeroOrNull" placeholder="" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">说明</label>
							<div class="layui-input-block">
								<input type="text" name="instock.is_remark" id="is_remark" oninput="search(this)" class="layui-input" placeholder="模糊搜索" autocomplete="off" 
									style="position:absolute;z-index:2;width:86%;" >
			                    <select type="text" id="SelectId-is_remark" lay-filter="TextSelect-lay-filter" autocomplete="off" class="layui-select" lay-search>
			                        <option value="">清空</option>
			                        <option th:each="item:${instocks}" th:value="${item.is_remark}">[[${item.is_remark}]]</option>
			                    </select>
							</div>
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">所在仓库</label>
							<div class="layui-input-block">
								<select name="instock.is_roomid">
									<option value="">未选择</option>
									<option th:each="item:${storehouses}" th:value="${item.store_id}">[[${item.store_name}]]</option>
								</select>
							</div>
						</div>
						
						<div class="layui-inline" style="margin-right: 0px;">
							<label class="layui-form-label">剩余月数</label>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="ds_month_min" lay-verify="geZeroOrNull" lay-verType="tips" placeholder="" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">~</div>
							<div class="layui-input-inline" style="width: 92px;">
								<input type="text" name="ds_month_max" lay-verify="geZeroOrNull" lay-verType="tips" placeholder="" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-inline" style="width: 398px;">
							<label class="layui-form-label">到期时间</label>
							<div class="layui-input-inline">
								<input type="text" name="instock.is_enddate_interval" id="is_enddate_interval" 
									class="layui-input" placeholder=" - 区间 - " style="width: 294px;">
							</div>
						</div>
						
						<!-- 按钮区域 -->
						<div class="layui-inline" style="margin-left: 20px;">
							<!-- 提交按钮 -->
							<button class="layui-btn btn-submit-drugstock" lay-submit lay-filter="LAY-drugstock-front-submit">
								<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
							</button>
							<!-- 重置按钮 -->
							<button class="layui-btn btn-submit-drugstock" lay-submit lay-filter="LAY-drugstock-front-reset">
								<i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn"></i>
							</button>
						</div>
					</div>
				</div>
				
				<div class="layui-card-body">
					<!-- 表格上的按钮组 -->
					<div class="layui-row" style="padding-bottom: 10px;">
					    <div class="layui-col-md6">
					    	<label class="layui-form-label">库存：</label>
							<button class="layui-btn layui-btn-danger" onclick="sumMax(0)">
								<i class="layui-icon layui-icon-down layuiadmin-button-btn"></i>库存为0
							</button>
							<button class="layui-btn layui-btn-warm" onclick="sumMax(50)">
								<i class="layui-icon layui-icon-down layuiadmin-button-btn"></i>库存小于50
							</button>
							<button class="layui-btn layui-btn-normal" onclick="sumMax(100)">
								<i class="layui-icon layui-icon-down layuiadmin-button-btn"></i>库存小于100
							</button>
							<button class="layui-btn" onclick="sumMax(500)">
								<i class="layui-icon layui-icon-down layuiadmin-button-btn"></i>库存小于500
							</button>
						</div>
						<div class="layui-col-md6">
							<label class="layui-form-label">有效期：</label>
							<button class="layui-btn layui-btn-danger" onclick="surplusMonth(-1200,0)">
								<i class="layui-icon layui-icon-triangle-d layuiadmin-button-btn"></i>已过期
							</button>
							<button class="layui-btn layui-btn-warm" onclick="surplusMonth(1,1)">
								<i class="layui-icon layui-icon-triangle-d layuiadmin-button-btn"></i>剩余0~1月
							</button>
							<button class="layui-btn layui-btn-normal" onclick="surplusMonth(2,3)">
								<i class="layui-icon layui-icon-triangle-d layuiadmin-button-btn"></i>剩余2~3月
							</button>
							<button class="layui-btn" onclick="surplusMonth(4,6)">
								<i class="layui-icon layui-icon-triangle-d layuiadmin-button-btn"></i>剩余4~6月
							</button>
						</div>
					</div>

					<!-- 表格主题 -->
					<table id="drugstock-table" lay-filter="drugstock-table"></table>
				</div>
				
				<!-- 设置样式的js代码 -->
				<script type="text/html" id="imgTpl">
					<img style="display: inline-block; width: 50%; height: 100%;" src= {{ d.avatar }}>
        		</script>
       			<!-- 设置操作栏的按钮样式 --><!--  style="background-color:#6faeff;" -->
        		<script type="text/html" id="table-drugstock-operatecolumn">
					{{#  if(d.ds_num<= 0){ }}
						<button class="layui-btn layui-btn-warm layui-btn-xs" lay-event="exception">
							<i class="layui-icon layui-icon-delete"></i>
							没有库存
						</button>
					{{#  } else if(d.ds_num> 0 && d.ds_num<= 50){ }}
						<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="exception">
							<i class="layui-icon layui-icon-delete"></i>
							库存不足
						</a>
					{{#  } }}

					{{#  if(d.instock.is_effectivetime <= d.ds_passedmonth){ }}
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="exception">
							<i class="layui-icon layui-icon-delete"></i>
							已过期
						</a>
					{{#  } else if(d.instock.is_effectivetime <= d.ds_passedmonth + 1){ }}
						<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="exception">
							<i class="layui-icon layui-icon-delete"></i>
							即将过期
						</a>
					{{#  } }}
					
        		</script>
			</div>
		</div>

		<!-- 引入layui框架 -->
		<script th:src="@{/layuiadmin/layui/layui.js}"></script>
		<!-- 引入公共layui代码 -->
		<script type="text/javascript" th:src="@{/public/warehouse/publicsetting.js}"></script>
		<script>
			//启动layui语法：config全局配置
			layui.config({
				base: '[[@{/layuiadmin/}]]' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'warehouse/drugstock', 'table' ,'laydate'], function() {//调用layui的js文件，注意路径，直接在/layuiadmin/modules/文件夹下
				//生成标签的对应对象
				var $ = layui.$,
					form = layui.form,
					table = layui.table,
					laydate = layui.laydate;
				//监听重置搜索
				form.on('submit(LAY-drugstock-front-reset)', function(data) {
					location.reload();
				});

				//监听搜索
				form.on('submit(LAY-drugstock-front-submit)', function(data) {
					var field = data.field;

					//执行重载，重新加载表格数据
					table.reload('drugstock-table', {
						where: field
					});
				});

				//事件。当标签的 data-type=""字段等于这里的字段名时，执行对应方法
				var active = {
					//批量删除按钮的事件
					aaaaa: function() {
						$("name=['ds_num_min']").val();
					},
				};
				
				laydate.render({
					elem: '#is_enddate_interval',
					range: "~"
				});
				
				//不知道是什么
				$('.layui-btn.btn-submit-drugstock').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				
				window.sumMax = function (parameter) {
					//执行重载，重新加载表格数据
					table.reload('drugstock-table', {
	                    where : {
	                    	//请求发送的键值对数据
	                        ds_num_max : parameter,
	                    },
	                });
				}
				window.surplusMonth = function (parameter1,parameter2) {
					//执行重载，重新加载表格数据
					table.reload('drugstock-table', {
	                    where : {
	                    	//请求发送的键值对数据
	                        ds_month_min : parameter1,
	                        ds_month_max : parameter2,
	                    },
	                });
				}
			});
		</script>
	</body>
</html>
